﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using TenderSampleApp.Areas.DAK.Models;

namespace TenderSampleApp.Areas.DAK.Controllers
{
    public class DAKValidRequestController : Controller
    {
        //
        // GET: /DAK/DAKValidRequest/
        [Authorize(Roles = "DAK")]
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        [Authorize(Roles = "DAK")]
        public ActionResult LoadExcelBankFile()
        {
            return View();
        }
        //
        [HttpPost]
        [Authorize(Roles = "DAK")]
        public ActionResult LoadExcelBankFile(HttpPostedFileBase file)
        {
            DAKDAL dl = new DAKDAL();
            int id = 0;
            if (file != null && file.ContentLength > 0)
            {
                // extract only the fielname
                var fileName = Path.GetFileName(file.FileName);
                // store the file inside ~/App_Data/uploads folder
                var path = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
                file.SaveAs(path);
                id= dl.ReadDBFFileBank(path);
            }
            // redirect back to the index action to show the form once again
            return RedirectToAction("CheckResultBankFile", new {fbid=id });
        }

        [Authorize(Roles = "DAK")]
        public ActionResult CheckResultBankFile(int fbID=0)
        {
            if (fbID == 0)
                return RedirectToAction("LoadExcelBankFile");
            DAKDAL dl = new DAKDAL();
            List<BankFileResultModel> listbfrm = dl.CheckExpenseByBankFile(fbID);

           return View(listbfrm);
        }

        [Authorize(Roles = "DAK")]
        public ActionResult DetailsOfCheckResultBankFile(string reqNum)
        {
        //    if (fbID == 0)
        //        return RedirectToAction("LoadExcelBankFile");
        //    DAKDAL dl = new DAKDAL();
        //    List<BankFileResultModel> listbfrm = dl.CheckExpenseByRequestNumber(fbID);

            return View();
        }
    


    }
}
